<?php 
define('current_dir', dirname(__FILE__) . '/');
global $_GLOBAL;
include_once(current_dir . 'common.php');
//=====================================
include_once("Mobile_Detect.php");
$detect = new Mobile_Detect();
 
if (!$detect->isMobile()) {
    echo "请用手机访问。";
    exit;
}
//=====================================
$c = new common();
$action = $c->accept('action', 'P');
if($action == "findpass") {  //业务员登录
	$username = $c->accept('username', 'P');
	$err = 0;
	if($username =="") {
		$err = -1;
	} else if (!preg_match("/^1[0-9]{10}$/", $username)) {
		$err = -2;
	}
	$c->init();
	if($err == 0) {
		$db_table = db_prefix . "member";
		$db_where = "username='$username' AND isclass=1";
		$db_sql = "SELECT * FROM $db_table WHERE $db_where";
		$rsMember = $_GLOBAL['db']->fetch_first($db_sql);
		if ($rsMember) {
			$password = mt_rand(10000000, 99999999);
			$password2 = md5($password);
			$db_set = "password='$password2'";
			$_GLOBAL['db']->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
			$c->membersmssend('memberpwsms',$username,$password); //手机短信
			$err = 2;
		} else {
			$err = -7;
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>找回密码</title>
<link type="text/css" rel="stylesheet" href="mobile.css" />
</head>
<body>
<div class="mobile">
	<div class="t" style="text-align:left;">找回密码</div>
	<form name="mainform" method="post" action="lostpasswd.php">
    <dl>
    	<dd><label>手机号：</label><input type="text" id="username" class="u" size="20" name="username" value="" /></dd>
    	 <dd class="<?php if($err==2) { echo "success";} else { echo "text";}?>"><?php echo $c->message($err);?></dd>
        <dd class="slogin"><input type="hidden" id="action" name="action" value="findpass" /><input name="submit" type="submit" class="buttonface" value="确定提交"/></dd>
		<?php if($err==2) {?>
		<dd class="slogin"><a href="index.php"></a>返回登录</dd>
		<?php }?>
    </dl>
    </form>
</div>
</body>
</html>